# -*- coding: utf-8 -*-
# https://blog.csdn.net/weixin_52040868
# 公众号：测个der
# 微信：qing_an_an

import sys
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.Qt import *
from PyQt5.QtCore import QDate
from PyQt5 import QtCore


class Lendar(QWidget):
    def __init__(self):
        super(Lendar, self).__init__()
        self.setUI()

    def setUI(self):
        self.cal = QCalendarWidget(self)
        # 设定日期范围
        self.cal.setMinimumDate(QDate(1980, 1, 1))
        self.cal.setMaximumDate(QDate(3000, 1, 1))
        # 设置网格可见
        self.cal.setGridVisible(True)
        self.cal.move(20, 20)
        # 绑定槽函数
        self.cal.clicked[QtCore.QDate].connect(self.showData)

        self.label = QLabel(self)
        # 设置标签的文本为日历控件所选中的日期，并转为str数据显示
        date = self.cal.selectedDate()
        self.label.setText(date.toString("yyyy-MM-dd dddd"))
        self.label.move(20, 300)
        # 设定位置
        self.setGeometry(100, 100, 400, 350)

        self.setWindowTitle("示例")

    def showData(self, date):
        # 绑定槽函数，点击切换日期的时候label信息变更
        self.label.setText(date.toString("yyyy-MM-dd dddd"))


if __name__ == '__main__':
    app = QApplication(sys.argv)
    lender = Lendar()
    lender.show()
    sys.exit(app.exec_())
